package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.CoachModel;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.TimeUtil;

/**
 * Created by zyh on 2017/12/19.
 */

public class CoachListAdapter extends MyBaseAdapter<CoachModel.Data> {

    public CoachListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        CoachViewHolder holder;
        if (view == null) {
            holder = new CoachViewHolder();
            view = layoutInflater.inflate(R.layout.item_coach_list, viewGroup, false);
            holder.title = view.findViewById(R.id.title);
            holder.btn = view.findViewById(R.id.btn);
            holder.time = view.findViewById(R.id.time);
            view.setTag(holder);
        } else
            holder = (CoachViewHolder) view.getTag();

        final CoachModel.Data item = getItem(i);
        if (item != null) {
            holder.title.setText(item.getTitle());
//            holder.title.getPaint().setFakeBoldText(true);
            holder.time.setText(TimeUtil.format(item.getCreateDate()));
            holder.btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    IntentManager.goCoachInterpretationActivity(context, item.getUuid());
                }
            });
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    IntentManager.goCoachPolicyDetailActivity(context, item.getUuid(), item.getTitle(), item.getCreateDate());
                }
            });
        }
        return view;
    }

    private class CoachViewHolder {
        TextView title, time;
        ImageView btn;
    }
}
